import { VxeGridProps } from 'vxe-table';
import { BizPriceVo } from '@/api/operation/price/types';

export function getTableConfig(): VxeGridProps<BizPriceVo> {
  return {
    id: 'tenant',
    loading: false,
    height: 'auto',
    autoResize: true,
    border: 'inner',

    resizable: true,
    showOverflow: 'tooltip',
    stripe: true,
    rowConfig: {
      isHover: true,
      keyField: 'id'
      // height: 56
    },
    customConfig: {
      storage: true
    },
    columns: [
      { title: '序号', type: 'seq', width: 50 },
      { sortable: true, field: 'priceId', title: '定价ID', width: 180 },
      { sortable: true, field: 'name', title: '定价名称' },
      { sortable: true, field: 'scope', title: '类型', slots: { default: 'scope' } },
      {
        field: 'content',
        title: '定价方案',
        formatter: ({ row }) => {
          if (typeof row.price === 'number') {
            if (row.priceType === '1') {
              return (row.price / 100).toFixed(2) + '元/' + row.quantity / 60 + '分钟';
            } else {
              return (row.price / 100).toFixed(2) + '元/' + row.quantity + '升';
            }
          } else {
            // 如果是字符串类型，可以先转换为数字再进行格式化
            return '-';
          }
        }
      },
      {
        field: 'vendors',
        title: '适用对象',
        formatter: ({ row }) => (row.vendors && row.vendors.length ? row.vendors.map((it: any) => it.vendorName).join() : '全局')
      },
      { sortable: true, field: 'priceType', title: '配置类型', slots: { default: 'type' } },
      { sortable: true, field: 'remarks', title: '备注' },
      { sortable: true, field: 'createByName', title: '创建人' },
      { sortable: true, field: 'createTime', title: '创建时间' },
      { sortable: true, field: 'handle', title: '操作', width: '140px', slots: { default: 'handle' } }
    ],
    data: [] as BizPriceVo[]
  };
}
